/**********************************************************************************
 *  jcw - this is a environment for solving japan crosswords by users on computer *
 *  Copyright (C) 2008 by pluton <plutonpluton@mail.ru>                           *
 *                                                                                *
 *  This program is free software; you can redistribute it and/or modify          *
 *  it under the terms of the GNU General Public License as published by          *
 *  the Free Software Foundation; either version 2 of the License, or             *
 *  (at your option) any later version.                                           *
 *                                                                                *
 *  This program is distributed in the hope that it will be useful,               *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of                *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
 *  GNU General Public License for more details.                                  *
 *                                                                                *
 *  You should have received a copy of the GNU General Public License along       *
 *  with this program; if not, write to the Free Software Foundation, Inc.,       *
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.                   *
 *********************************************************************************/

#include "colorselector.h"
#include "palette.h"

ColorSelector::ColorSelector(Palette::paletteType t, QWidget* parent, Qt::WindowFlags f)
	: QWidget(parent, f)
{
	QVBoxLayout* layout = new QVBoxLayout;
	QLabel* l;
	if (t == Palette::Brush)
		l = new QLabel(tr("Brush"));
	else if (t == Palette::Layer)
		l = new QLabel(tr("Layer"));
	l->setAlignment(Qt::AlignCenter);
	layout->addWidget(l);
	p = new Palette(t, parent, f);
	connect(p, SIGNAL(currItemChanged(quint16)), this, SIGNAL(currItemChanged(quint16)));

	layout->addWidget(p);
	setLayout(layout);
}

ColorSelector::~ColorSelector()
{
}

void ColorSelector::layerSet(quint16 c)
{
	if (p->getType() == Palette::Brush)
	{
		if (c - 1 >= 0)
			p->updatePixmap(c - 1);
	}
	else if (p->getType() == Palette::Layer)
		p->updatePixmap(c);

	if (p->getType() == Palette::Brush)
	{
		if (c > 0)
			p->block();
		else
			p->unblock();
	}
}

void ColorSelector::setColorMap(ColorCW::ColorMap* colorMap, quint16 cmCnt)
{
	p->setColorMap(colorMap, cmCnt);
}
